package com.inspectortime.webapp.inspector;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.inspectortime.domain.InspectorCompany;
import com.inspectortime.domain.billing.Invoice;
import com.inspectortime.repository.Repository;
import com.inspectortime.webapp.util.HttpSessionUtils;

/**
 * Prepares data for the "Company Settings" page
 * 
 * @author bones
 *
 */
public class SettingsController implements Controller {

	private Repository repository;
	private String returnView;
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		InspectorCompany company = HttpSessionUtils.retrieveLoggedInCompany(request, repository);
		
		ModelAndView mv = new ModelAndView(this.returnView);
		mv.addObject("inspectorCompany", company);
		List<Invoice> invoices = repository.findUnpaidInvoicesForCompanyId((String) company.getId());
		mv.addObject("invoices", invoices);
		return mv;
	}
	
	public void setReturnView(String returnView) {
		this.returnView = returnView;
	}

	public void setRepository(Repository repository) {
		this.repository = repository;
	}
	
}
